package minh.bac.wcbrazil2014.adapter;

import java.util.List;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import minh.bac.wcbrazil2014.R;
import minh.bac.wcbrazil2014.object.XepHangBangObj;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewXepHangAdapter extends ArrayAdapter<XepHangBangObj> {

	Context context;
	int resource;
	List<XepHangBangObj> objects;
	DisplayImageOptions displayImageOption;

	public ListViewXepHangAdapter(Context context, int resource,
			List<XepHangBangObj> objects, DisplayImageOptions displayImageOption) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resource = resource;
		this.objects = objects;
		this.displayImageOption = displayImageOption;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		ViewHolder holderChild;
		if (convertView == null) {
			holderChild = new ViewHolder();
			convertView = inflater.inflate(resource, parent, false);
			//
			holderChild.bangdau = (TextView) convertView
					.findViewById(R.id.tv_group);
			holderChild.doibong = (TextView) convertView
					.findViewById(R.id.tv_doibong1);
			holderChild.image = (ImageView) convertView
					.findViewById(R.id.imageTeam1);
			holderChild.tran = (TextView) convertView
					.findViewById(R.id.tv_tran1);
			holderChild.thb = (TextView) convertView.findViewById(R.id.tv_thb1);
			holderChild.hieuso = (TextView) convertView
					.findViewById(R.id.tv_hieuso1);
			holderChild.diem = (TextView) convertView
					.findViewById(R.id.tv_diem1);
			//
			holderChild.doibong2 = (TextView) convertView
					.findViewById(R.id.tv_doibong2);
			holderChild.image2 = (ImageView) convertView
					.findViewById(R.id.imageTeam2);
			holderChild.tran2 = (TextView) convertView
					.findViewById(R.id.tv_tran2);
			holderChild.thb2 = (TextView) convertView
					.findViewById(R.id.tv_thb2);
			holderChild.hieuso2 = (TextView) convertView
					.findViewById(R.id.tv_hieuso2);
			holderChild.diem2 = (TextView) convertView
					.findViewById(R.id.tv_diem2);
			//
			holderChild.doibong3 = (TextView) convertView
					.findViewById(R.id.tv_doibong3);
			holderChild.image3 = (ImageView) convertView
					.findViewById(R.id.imageTeam3);
			holderChild.tran3 = (TextView) convertView
					.findViewById(R.id.tv_tran3);
			holderChild.thb3 = (TextView) convertView
					.findViewById(R.id.tv_thb3);
			holderChild.hieuso3 = (TextView) convertView
					.findViewById(R.id.tv_hieuso3);
			holderChild.diem3 = (TextView) convertView
					.findViewById(R.id.tv_diem3);
			//
			holderChild.doibong4 = (TextView) convertView
					.findViewById(R.id.tv_doibong4);
			holderChild.image4 = (ImageView) convertView
					.findViewById(R.id.imageTeam4);
			holderChild.tran4 = (TextView) convertView
					.findViewById(R.id.tv_tran4);
			holderChild.thb4 = (TextView) convertView
					.findViewById(R.id.tv_thb4);
			holderChild.hieuso4 = (TextView) convertView
					.findViewById(R.id.tv_hieuso4);
			holderChild.diem4 = (TextView) convertView
					.findViewById(R.id.tv_diem4);

			convertView.setTag(holderChild);
		} else
			holderChild = (ViewHolder) convertView.getTag();

		holderChild.bangdau.setText(objects.get(position).getBang());
		
		holderChild.doibong.setText(objects.get(position).getXephang1()
				.getDoiBong());
		holderChild.tran.setText(objects.get(position).getXephang1().getTran());
		holderChild.thb.setText(objects.get(position).getXephang1().getThb());
		holderChild.hieuso.setText(objects.get(position).getXephang1()
				.getHieuSo());
		holderChild.diem.setText(objects.get(position).getXephang1().getDiem());
		//

		holderChild.doibong2.setText(objects.get(position).getXephang2()
				.getDoiBong());
		holderChild.tran2
				.setText(objects.get(position).getXephang2().getTran());
		holderChild.thb2.setText(objects.get(position).getXephang2().getThb());
		holderChild.hieuso2.setText(objects.get(position).getXephang2()
				.getHieuSo());
		holderChild.diem2
				.setText(objects.get(position).getXephang2().getDiem());
//		//

		holderChild.doibong3.setText(objects.get(position).getXephang3()
				.getDoiBong());
		holderChild.tran3
				.setText(objects.get(position).getXephang3().getTran());
		holderChild.thb3.setText(objects.get(position).getXephang3().getThb());
		holderChild.hieuso3.setText(objects.get(position).getXephang3()
				.getHieuSo());
		holderChild.diem3
				.setText(objects.get(position).getXephang3().getDiem());
//		//
//
		holderChild.doibong4.setText(objects.get(position).getXephang4()
				.getDoiBong());
		holderChild.tran4
				.setText(objects.get(position).getXephang4().getTran());
		holderChild.thb4.setText(objects.get(position).getXephang4().getThb());
		holderChild.hieuso4.setText(objects.get(position).getXephang4()
				.getHieuSo());
		holderChild.diem4
				.setText(objects.get(position).getXephang4().getDiem());

		//
		String urlImage, urlImage2, urlImage3, urlImage4;
		urlImage = objects.get(position).getXephang1().getImage();
		urlImage2 = objects.get(position).getXephang2().getImage();
		urlImage3 = objects.get(position).getXephang3().getImage();
		urlImage4 = objects.get(position).getXephang4().getImage();
		// if (urlImage == null)
		// urlImage = "";
		//
		// if (urlImage2 == null)
		// urlImage2 = "";
		//
		// if (urlImage3 == null)
		// urlImage3 = "";
		//
		// if (urlImage4 == null)
		// urlImage4 = "";

		// load image
		ImageLoader.getInstance().displayImage(urlImage, holderChild.image,
				displayImageOption);
		ImageLoader.getInstance().displayImage(urlImage2, holderChild.image2,
				displayImageOption);
		ImageLoader.getInstance().displayImage(urlImage3, holderChild.image3,
				displayImageOption);
		ImageLoader.getInstance().displayImage(urlImage4, holderChild.image4,
				displayImageOption);

		return convertView;
	}

	private class ViewHolder {
		TextView bangdau, doibong, tran, thb, hieuso, diem;
		ImageView image;
		TextView doibong2, tran2, thb2, hieuso2, diem2;
		ImageView image2;
		TextView doibong3, tran3, thb3, hieuso3, diem3;
		ImageView image3;
		TextView doibong4, tran4, thb4, hieuso4, diem4;
		ImageView image4;
	}

}
